package com.soar.recruitment.module.user.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.soar.recruitment.R;
import com.soar.recruitment.common.ui.fragment.SOARBaseBackFragment;
import com.soar.recruitment.common.ui.view.MyEditView;
import com.soar.recruitment.common.ui.view.roundview.RoundTextView;
import com.soar.recruitment.common.util.SoarLoadDialog;
import com.soar.recruitment.module.user.bll.controller.LoginContrats;
import com.soar.recruitment.module.user.bll.controller.LoginPresenter;
import com.soar.recruitment.module.user.ui.activity.RegisterActivity;
import com.soar.recruitment.module.user.ui.activity.ResetPwdActivity;

import butterknife.BindView;

/**
 * 登录
 * Created by chriswen on 2017/6/16.
 */
public class LoginFragment extends SOARBaseBackFragment implements LoginContrats.View {

    private LoginContrats.Presenter mPresenter;

    @BindView(R.id.toolbar)
    Toolbar toolbar;

    @BindView(R.id.tv_forget_pwd)
    TextView tv_forget_pwd;
    @BindView(R.id.tv_register)
    TextView tv_register;

    @BindView(R.id.phoneEditView)
    MyEditView phoneEditView;
    @BindView(R.id.passwordeEditView)
    MyEditView passwordeEditView;
    @BindView(R.id.rvt_login)
    RoundTextView rvt_login;

    public static LoginFragment newInstance() {
        Bundle args = new Bundle();
        LoginFragment fragment = new LoginFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int initLayout() {
        return R.layout.fragment_login;
    }

    @Override
    public void initVariable() {
        mPresenter = new LoginPresenter(this);
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        initToolbarNavBlack(toolbar);
        toolbar.setTitle("登录");

        tv_forget_pwd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 忘记密码
                startActivity(new Intent(_mActivity, ResetPwdActivity.class));
            }
        });
        tv_register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 注册
                startActivity(new Intent(_mActivity, RegisterActivity.class));
            }
        });
        rvt_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mPresenter.signLogin();
            }
        });
    }

    @Override
    public void initData() {

    }

    @Override
    public String getPhoneNum() {
        return phoneEditView.getText();
    }

    @Override
    public String getPwdNum() {
        return passwordeEditView.getText();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (mPresenter != null) {
            mPresenter.destory();
        }
    }

    @Override
    public void goNext() {
        _mActivity.onBackPressed();
    }

    @Override
    public void showLoading(String msg) {
        SoarLoadDialog.showLoadDialog(mActivity, msg);
    }

    @Override
    public void closeLoading() {
        SoarLoadDialog.closeLoadDialog();
    }
}
